package de.rs.espresso.algorithms.minimumcover.model;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;

public class Solution<T> implements Cloneable {

	private List<Column<T>> columns = new ArrayList<Column<T>>();

	private int size;

	public Solution(List<Column<T>> columns) {
		this.columns.addAll(columns);		
		this.size = columns.size();
	}

	public Solution() {
		this.size = 0;
	}

	public BitSet toBitSet() {
		BitSet result = new BitSet(size);
		
		for(Column<T> c : columns) 
			result.set(c.getPosition());
		
		return result;
	}
	
	
	public List<T> toList() {
		List<T> result = new ArrayList<T>();
		for(Column<T> c : columns) {
			result.add(c.getElement());			
		}
		return result;
	}
	
	public int getCost() {
		return columns.size();
	}

	public void add(List<Column<T>> p) {
		columns.addAll(p);
		
	}
	
	public void add(Column<T> c) {
		columns.add(c);
		
	}

	public void removeColumn(int rowNumber) {
		for(Column<T> c : columns) {
			if(c.getPosition()==rowNumber) {
				columns.remove(c);
				break;
			}
		}
		
	}
	
	public Solution<T> clone() {
		return new Solution<T>(columns);
		
	}
	


}